﻿// Ŭnicode please

#include "SREngine.h"
#include "SRMacro.h"
#include "SRRenderer.h"

using std::auto_ptr;

namespace sora
{
	Engine::Engine()
		: screenWidth_(0), screenHeight_(0)
	{
	}
	Engine::~Engine()
	{
	}
	Engine &Engine::engine()
	{
		static Engine e;
		return e;
	}
	void Engine::cleanup()
	{
		app_ = auto_ptr<RenderApp>(NULL);
	}

	void Engine::setScreenSize(int width, int height)
	{
		SR_ASSERT(width > 0 && height > 0);
		screenWidth_ = width;
		screenHeight_ = height;
	}
	int Engine::screenWidth() const 
	{
		SR_ASSERT(screenWidth_ > 0);
		return screenWidth_; 
	}
	int Engine::screenHeight() const 
	{
		SR_ASSERT(screenHeight_ > 0);
		return screenHeight_; 
	}

	void Engine::setApp(RenderApp *app)
	{
		app_ = auto_ptr<RenderApp>(app);
	}

	void Engine::draw() const
	{
		static int tick = 0;
		app_->render(tick, screenWidth(), screenHeight());
		tick++;
	}
	void Engine::update(float dt)
	{
	}

	namespace engine
	{
		void draw() { Engine::engine().draw(); }
		void update(float dt) { Engine::engine().update(dt); }
	}
}